package com.elm.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCUtil {
	//1.数据库地址  (根据不同的数据标准是不一样)
	  private  final  static String DBURL = "jdbc:mysql://localhost:3306/hungry_elm?useUnicode=true&characterEncoding=UTF8";
	  //2.设置用户和密码
	  private  final  static String  USERNAME = "root";
	  private  final  static String  PASSWORD = "root";
	  //3.设置驱动名称 (根据不同的数据标准是不一样)
	  private  final  static String  DBDRIVER = "com.mysql.jdbc.Driver";
	  
	  public static Connection getConnection(){
		  Connection  con = null;
		  try {
			Class.forName(DBDRIVER);
			con=DriverManager.getConnection(DBURL, USERNAME, PASSWORD);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  return con;
	  }
	  public static void closeJDBC(PreparedStatement pst,Connection con){
		 
			  try {
				  if(pst!=null){
				pst.close();
				  }
				if(con!=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
		}
	 }
}
